package cc.catface.service;

import cc.catface.dao.biz.app.ApUser;
import cc.catface.dao.biz.app.mapper.ApUserMapperServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;

public class BaseService {
    @Autowired
    private ApUserMapperServiceImpl apUserMapperService;

    protected long getUserIdByPhone(String phone) {
        ApUser user = apUserMapperService.getOne(new QueryWrapper<ApUser>().eq("phone", phone));
        if (user == null) throw new RuntimeException("未查询到用户(getUserIdByPhone)");
        return user.getId();
    }

    protected ApUser getUserByUserId(long userId) {
        ApUser user = apUserMapperService.getOne(new QueryWrapper<ApUser>().eq("id", userId));
        if (user == null) throw new RuntimeException("未查询到用户(getUserByUserId)");
        return user;
    }
}
